﻿namespace E6BTest
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Conducts the Ground Speed tests for the E6B.
    /// </summary>
    [TestClass]
    public class E6BGroundSpeedTests : E6BTests
    {
        /// <summary>
        /// Configures the test suite's E6B with the speeds and angles used for
        /// each test.
        /// </summary>
        /// <param name="context">The test context.</param>
        [ClassInitialize()]
        public static new void SuiteSetup(TestContext context)
        {
            E6BTests.SuiteSetup(context);
        }

        /// <summary>
        /// Cleans up any resources used by the E6B.
        /// </summary>
        [ClassCleanup()]
        public static new void SuiteCleanup()
        {
            E6BTests.SuiteCleanup();
        }

        /// <summary>
        /// Random wind position test.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestRandom()
        {
            WindSpeed = 15;
            TrueAirspeed = 121;
            WindDirection = 190;
            Course = 180;
            ConfigureE6B();

            double expected = 106;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// Calm wind test.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestCalm()
        {
            WindSpeed = 0;
            TrueAirspeed = 121;
            WindDirection = 190;
            Course = 180;
            ConfigureE6B();

            double expected = 121;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// Headwind test.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestHeadwind()
        {
            WindSpeed = 19;
            TrueAirspeed = 121;
            WindDirection = 180;
            Course = 180;
            ConfigureE6B();

            double expected = 102;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// Tailwind test.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestTailwind()
        {
            WindSpeed = 19;
            TrueAirspeed = 121;
            WindDirection = 0;
            Course = 180;
            ConfigureE6B();

            double expected = 140;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// Crosswind test from the left.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestXWLeft()
        {
            WindDirection = 90;
            WindSpeed = 50;
            TrueAirspeed = 121;
            Course = 180;
            ConfigureE6B();

            double expected = 110;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// Crosswind test from the right.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestXWRight()
        {
            WindDirection = 270;
            WindSpeed = 50;
            TrueAirspeed = 121;
            Course = 180;
            ConfigureE6B();

            double expected = 110;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// 45 degree crosswind test from the right.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestXWRight45()
        {
            WindDirection = 225;
            WindSpeed = 50;
            TrueAirspeed = 121;
            Course = 180;
            ConfigureE6B();

            double expected = 80;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }

        /// <summary>
        /// 45 degree crosswind test from the left.
        /// </summary>
        [TestMethod]
        public void GroundSpeedTestXWLeft45()
        {
            WindDirection = 135;
            WindSpeed = 50;
            TrueAirspeed = 121;
            Course = 180;
            ConfigureE6B();

            double expected = 80;  // based on hand calculations
            Assert.AreEqual(expected, Computer.TrueGroundspeed());
        }
    }
}